package org.kealinghornets.jchuah.buttons;

import android.content.Intent;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Toast;



public class MainActivity extends ActionBarActivity {


View midcircle;




    public void togglecircle(int id) {

        View circle;
        circle = findViewById(id);

        if (circle.getVisibility() == View.VISIBLE) {
            circle.setVisibility(View.INVISIBLE);
        } else {

            circle.setVisibility(View.VISIBLE);
        }
    }


    public void push_button(){

        View leftcircle = findViewById(R.id.left_circle);
        View midcircle = findViewById(R.id.mid_circle);
        View rightcircle = findViewById(R.id.right_circle);

        if(leftcircle.getVisibility() == View.INVISIBLE && midcircle.getVisibility() == View.INVISIBLE && rightcircle.getVisibility() == View.INVISIBLE){
             Toast.makeText(this,"you win",Toast.LENGTH_SHORT).show();
             startActivity(new Intent(this, Level2activity.class));
        }

    }


    public void push_button_left(View view) {
        Log.d("push_button", "BUTTON LEFT");

    togglecircle(R.id.left_circle);
    togglecircle(R.id.mid_circle);
        push_button();

    }

    public void push_button_mid(View view) {
        Log.d("push_button", "BUTTON MIDDLE");

        midcircle.setVisibility(View.INVISIBLE);
        push_button();

    }

    public void push_button_right(View view) {
        Log.d("push_button", "BUTTON RIGHT");

        togglecircle(R.id.left_circle);
        togglecircle(R.id.right_circle);
        push_button();

    }




    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        midcircle=findViewById(R.id.mid_circle);

    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }

}
